<?php

  /**
   * iJBlocks
   *
   * The iJEngineXML class provides unserialize and serialize data to XML
   *
   * @copyright Copyright (c) 2011, iJBlocks Progect
   */
  /*
   * Include reqired external class
   */
   include(DIR_EXTERNAL . 'php/xml/xml.php');

   class iJEngineXML {
    
    /**
     * xml data
     * @name $_xml
     * @var String
     * @access public
     */
     
    public static $_xml;
    
    /**
     * xml data
     * @name $_encoding
     * @var String
     * @access public
     */
    public static $_encoding = '';

    /**
     *
     * Class Constructuctor
     * @access public
     */
    public function __construct() {
      
    }
    

    /**
     *
     * This function returns data in array
     *
     * @param $xml - string, containing XML data
     * @param string $encoding  - encoding
     * @access public
     * @static
     */
    public static function toArray($xml) {
      return XML_unserialize($xml);
    }
    
    /**
     *
     * Gets array from XML file
     *
     * @param $file - string, path to xml file
     * @static
     */
     
    public static function getArrayFromXMLFile($path) {
        if(file_exists($path)) {
           $content = file_get_contents($path,FILE_TEXT);
           return XML_unserialize($content);
        } else {
            return null;
        }
    }

    /**
     *
     * This function returns data in XML string
     *
     * @param $xml - string, containing XML data
     * @param string $encoding  - encoding
     * @access public
     * @static
     */
    public static function toXML($xml, $encoding = '') {
      return XML_serialize($xml, $encoding);
    }
  }
?>